import { Component, OnInit,Output,Input,EventEmitter } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-units',
  templateUrl: './units.component.html',
  styleUrls: ['./units.component.scss']
})
export class UnitsComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    
  }

  @Output()  private  outer=new EventEmitter();
  @Input() puc_msg:any; 
  field1 = []     //table表格1-主表列字段集合
  data1 = {}      //table表格1-主表对象数据集合
  data1_dis = {}  //table表格1-主表对象禁用集合
  data1_sel = []  //table表格1-主表下拉框数据集合
  data1_att = []  //table表格1-主表自定义属性数据集合
 /**
   * 表格字段动态列集合生成
   */
  filed_tablelist() {
    this.interfaceService.postPage("/erp/common/fields/getfieldsbytype", { "type":"unitOption.OptionVo" }).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        this.field1=this.utilService.filed_list4(data.object);
        this.popup01_table();//初始化列表表格数据
      }
    }
    });
  }
  ngOnInit() {
    this.filed_tablelist()
  }



  unitStatus_list=JSON.parse(localStorage.getItem("unitStatus_list"))
  popup01_url='';
  popup01_para
  popup01 = false;

  popup01_show(url,para?): void {//弹窗事件，默认get传参，第二参数为post方法传参，格式{"xxx":"xxx"}
    this.popup01_url=url
    this.popup01_para=para;
    this.popup01 = true;
    this.popup01_table();
  }
  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url='';
    this.popup01_para='';
    this.popup01_ss1='';
    this.popup01_ss2='';
    this.popup01_ss3=''; 
    this.popup01_ss4=''; 
  }

  popup01_data={}
  popup01_ss1='';
  popup01_ss2='';
  popup01_ss3='';
  popup01_ss4='';
  popup01_table(){
    if(typeof(this.popup01_para) == "undefined"){
      this.popup01_listTable(this.popup01_url+"&unitCode="+this.popup01_ss1+"&unitName="+this.popup01_ss2+"&inputCode="+this.popup01_ss3+"&unitStatus="+this.popup01_ss4);
    }else{
      this.popup01_data={}
      Object.assign(this.popup01_data, this.popup01_para,{unitCode:this.popup01_ss1,unitName:this.popup01_ss2,inputCode:this.popup01_ss3,unitStatus:this.popup01_ss4});
      this.interfaceService.postPage(this.popup01_url,this.popup01_para).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
        if(data.code==200){
          this.popup01_listTable2(data.object.list);
        }
      }
      });
    }
  }
  indexTableId = 'popup01_tblist_units'
  popup01_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        
        var tab = this.utilService.getTable(url, "#" + this.indexTableId, this.field1)
       tab["title"] = '数据表'
       table.render(tab);
        table.on('rowDouble(popup01_tblist_units)', (obj)=>{
          this.popup01_hide();
          this.outer.emit(obj.data)       
         });
        
      });
      
    },50);
  
  }



  popup01_listTable2(url):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        
        var tab = this.utilService.getTable(url, "#" + this.indexTableId, this.field1)
       tab["title"] = '数据表'
       table.render(tab);
        table.on('rowDouble(popup01_tblist_units)', (obj)=>{
          this.popup01_hide();
          this.outer.emit(obj.data)       
         });
        
      });
      
    },50);
  
  }



}
